import cv2
import numpy as np

img = cv2.imread('1.jpg')
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)


lower_red = np.array([1, 160, 100])
upper_red = np.array([10, 255, 255])
mask1 = cv2.inRange(hsv, lower_red, upper_red)

lower_red2 = np.array([160, 200, 100])
upper_red2 = np.array([179, 255, 255])
mask2 = cv2.inRange(hsv, lower_red2, upper_red2)

lower_red3 = np.array([170, 200, 100])
upper_red3 = np.array([180, 255, 255])
mask3 = cv2.inRange(hsv, lower_red3, upper_red3)

mask_red = mask1 + mask2 + mask3

kernel = np.ones((5,5),np.uint8)

erosion = cv2.erode(mask_red,kernel,iterations = 1)
dilation = cv2.dilate(erosion,kernel,iterations = 1)
contours, hierarchy = cv2.findContours(dilation,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

for cnt in contours:
    area = cv2.contourArea(cnt)
    if area > 1:
        (x, y, w, h) = cv2.boundingRect(cnt)
        cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)

cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
